﻿package mortal.game.view.chat.chatPrivate
{
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.layer3D.utils.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.menu.*;
    import mortal.mvc.core.*;

    public class ChatPrivateWindow extends ChatBaseWindow
    {
        protected var _playerInfo:SMiniPlayer;
        protected var _rightTitileText:GImageBitmap;
        protected var _headBg:GImageBitmap;
        protected var _headImageContainer:Sprite;
        protected var _headImage:GImageBitmap;
        protected var _btnLookInfo:GButton;
        protected var _btnAddFriend:GButton;
        protected var _btnInviteTeam:GButton;
        protected var _btnApplyTeam:GButton;
        protected var _sendFlower:GButton;
        protected var _textPlayerMsg:GTextFiled;
        protected var _tfCrossTip:GTextFiled;

        public function ChatPrivateWindow(param1:SMiniPlayer)
        {
            this._playerInfo = param1;
            return;
        }// end function

        override protected function initTargetIcon() : void
        {
            _chatIcon = new ChatPrivateIcon();
            _chatIcon.targetWindow = this;
            return;
        }// end function

        override protected function init() : void
        {
            super.init();
            this.updateGroupBtn();
            return;
        }// end function

        override protected function createRightPart() : void
        {
            super.createRightPart();
            this._rightTitileText = UIFactory.gImageBitmap(ImagesConst.ChatDuifangXingxi, 12, 6, _rightSprite);
            this._headBg = UIFactory.gImageBitmap(ImagesConst.ChatRoleHeadBg, 40, 50, _rightSprite);
            this._headImageContainer = new Sprite();
            this._headImageContainer.buttonMode = true;
            this._headImageContainer.x = 38;
            this._headImageContainer.y = 30;
            _rightSprite.addChild(this._headImageContainer);
            this._headImage = UIFactory.gImageBitmap("", 1, 6, this._headImageContainer);
            PlayerMenuRegister.Register(this._headImageContainer, this._playerInfo, PlayerMenuConst.ChatPrivateOpMenu);
            this._textPlayerMsg = UIFactory.gTextField("", 12, 140, 157, 185, _rightSprite);
            this._textPlayerMsg.multiline = true;
            this._textPlayerMsg.wordWrap = true;
            this._btnLookInfo = UIFactory.gButton(Language.getString(11514), 20, 330, 64, 22, _rightSprite);
            this._btnAddFriend = UIFactory.gButton(Language.getString(11515), 93, 330, 64, 22, _rightSprite);
            this._btnInviteTeam = UIFactory.gButton(Language.getString(11516), 20, 360, 64, 22, _rightSprite);
            this._btnApplyTeam = UIFactory.gButton(Language.getString(11517), 20, 360, 64, 22, _rightSprite);
            this._btnApplyTeam.visible = false;
            this._sendFlower = UIFactory.gButton(Language.getString(11518), 93, 360, 64, 22, _rightSprite);
            this._sendFlower.visible = false;
            this.updateInfo();
            return;
        }// end function

        override protected function addEventListeners() : void
        {
            super.addEventListeners();
            this._btnAddFriend.addEventListener(MouseEvent.CLICK, this.addFriendHandler);
            this._btnLookInfo.addEventListener(MouseEvent.CLICK, this.lookInfohandler);
            this._btnInviteTeam.addEventListener(MouseEvent.CLICK, this.inviteTeamHandler);
            this._btnApplyTeam.addEventListener(MouseEvent.CLICK, this.applyTeamHandler);
            this._sendFlower.addEventListener(MouseEvent.CLICK, this.onClickSendFlower);
            return;
        }// end function

        override protected function SendMsg() : void
        {
            if (_inputText.text && _btnSend.enabled)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChatPrivateSend, {content:getSendContent(), toPlayer:this._playerInfo, color:_color, isHasMapPoint:_isHasMapPoint}));
                _inputText.text = "";
                _btnSend.startCoolDown();
            }
            return;
        }// end function

        protected function addFriendHandler(event:MouseEvent) : void
        {
            PlayerMenuConst.Opearte(PlayerMenuConst.AddFriend, this._playerInfo);
            return;
        }// end function

        protected function inviteTeamHandler(event:MouseEvent) : void
        {
            PlayerMenuConst.Opearte(PlayerMenuConst.InvitedToTeam, this._playerInfo);
            return;
        }// end function

        protected function applyTeamHandler(event:MouseEvent) : void
        {
            PlayerMenuConst.Opearte(PlayerMenuConst.ApplyToTeam, this._playerInfo);
            return;
        }// end function

        protected function onClickSendFlower(event:MouseEvent) : void
        {
            return;
        }// end function

        protected function lookInfohandler(event:MouseEvent) : void
        {
            PlayerMenuConst.Opearte(PlayerMenuConst.LookInfo, this._playerInfo);
            return;
        }// end function

        public function getChatPlayerName() : String
        {
            return this._playerInfo.name;
        }// end function

        override public function getChatPlayerEntityId() : SEntityId
        {
            return this._playerInfo.entityId;
        }// end function

        public function getChatPlayerInfo() : SMiniPlayer
        {
            return this._playerInfo;
        }// end function

        public function updatePlayerMsg(param1:SMiniPlayer) : void
        {
            this._playerInfo = param1;
            this.updateInfo();
            return;
        }// end function

        protected function updateInfo() : void
        {
            _chatIcon.updateChatTarget(this._playerInfo);
            var _loc_1:* = !EntityUtil.isSameServerByRole(this._playerInfo.entityId);
            var _loc_2:* = NameUtil.getProxyName(this._playerInfo.entityId, true);
            var _loc_3:* = _loc_1 ? (_loc_2 + this._playerInfo.name) : (this._playerInfo.name);
            _textTitle.text = Language.getStringByParam(11519, _loc_3);
            this.title = _textTitle;
            this._headImage.imgUrl = AvatarUtil.getPlayerAvatarUrl(this._playerInfo.career, this._playerInfo.sex, AvatarUtil.Big);
            this._textPlayerMsg.htmlText = "<textformat leading=\'6\'>" + HTMLUtil.addColor(Language.getString(11520), "#FFFFFF") + _loc_3 + "<br/>" + HTMLUtil.addColor(Language.getString(11521), "#FFFFFF") + this._playerInfo.level + "<br/>" + HTMLUtil.addColor(Language.getString(11522), "#FFFFFF") + GameDefConfig.instance.getCarrer(this._playerInfo.career) + "<br/>" + HTMLUtil.addColor(Language.getString(11523), "#FFFFFF") + HTMLUtil.addColor(this._playerInfo.combat.toString(), GlobalStyle.colorAnjin) + "<br/>" + HTMLUtil.addColor(Language.getString(11524), "#FFFFFF") + HTMLUtil.addColor(this._playerInfo.signature ? (this._playerInfo.signature) : (Language.getString(21355)), GlobalStyle.colorHuang) + "</textformat>";
            this._btnAddFriend.visible = !_loc_1;
            return;
        }// end function

        public function updateGroupBtn() : void
        {
            var _loc_1:* = !EntityUtil.isSameServerByRole(this._playerInfo.entityId);
            if (!_loc_1)
            {
                if (Cache.instance.group.isInGroup && (Cache.instance.group.isCaptain || Cache.instance.group.memberInvite))
                {
                    this._btnInviteTeam.visible = true;
                    this._btnApplyTeam.visible = false;
                }
                else
                {
                    this._btnInviteTeam.visible = false;
                    this._btnApplyTeam.visible = true;
                }
            }
            return;
        }// end function

        override public function set visible(param1:Boolean) : void
        {
            super.visible = param1;
            this.updateGroupBtn();
            return;
        }// end function

    }
}
